<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of HoaDonDAO
 *
 * @author HOANGPHUC
 */
require ("../ENTITY/HoaDon.php");
class HoaDonDAO {

    public function __construct() {
        require ("../UTIL/MySQLProvider.php");
//        require ("../ENTITY/HoaDonDAO.php");

    }

    public static  function Create($column, $value) {

        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Insert("hoadon", $column, $value);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function Edit($column, $value, $whereColumn, $whereValue) {
        //require ("/UTIL/MySQLProvider.php");
        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Update("hoadon", $column, $value, $whereColumn, $whereValue);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function Remove($whereColumn, $whereValue) {
        // require ("/UTIL/MySQLProvider.php");
        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Delete("hoadon", $whereColumn, $whereValue);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function findAll() {
        // require ("/UTIL/MySQLProvider.php");

        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from hoadon");
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $theLoai = new HoaDon();
            $theLoai->SetId($r['ID']);
            $theLoai->SetKhachHang($r['MAKHACHHANG']);
            $theLoai->SetTongTIen($r['TONGTIEN']);
            $theLoai->SetTinhTrang($r['TINHTRANG']);
            $theLoai->SetGhiChu($r['GHICHU']);
            $theLoai->SetNgayLap($r['NGAYLAP']);
            $arr[$i] = $theLoai;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }

    public static function findByKhachHang($tenKhachHang) {
        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from hoadon, khachhang where khachhang.id = hoadon.makhachang and khachhang.ten like '%" .$tenKhachHang . "%'");
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $theLoai = new HoaDon();
            $theLoai->SetId($r['ID']);
            $theLoai->SetKhachHang($r['MAKHACHANG']);
            $theLoai->SetTongTIen($r['TONGTIEN']);
            $theLoai->SetTinhTrang($r['TINHTRANG']);
            $theLoai->SetGhiChu($r['GHICHU']);
            $theLoai->SetNgayLap($r['NGAYLAP']);
            $arr[$i] = $theLoai;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }

}

?>
